package com.example.myactspringboot.util;

/**
 * @Author Zhouchb
 * @Create 2024-03-26 22:50
 * @Description
 */

import cn.afterturn.easypoi.excel.export.styler.AbstractExcelExportStyler;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import org.apache.poi.ss.usermodel.*;

/**
 * @author ：xiezhijian
 * @date ：Created in 2020/3/18 11:55
 * @description：表头自定义
 * @parameter：
 * @modified By：
 * @version: $
 */
public class NewExcelExportStylerDefaultImpl extends AbstractExcelExportStyler implements IExcelExportStyler {
    public NewExcelExportStylerDefaultImpl(Workbook workbook) {
        super.createStyles(workbook);
    }

    @Override
    public CellStyle getTitleStyle(short color) {
        CellStyle titleStyle = workbook.createCellStyle();
        Font font = this.workbook.createFont();
        font.setBold(true); // 字体加粗
        titleStyle.setFont(font);
        titleStyle.setAlignment(HorizontalAlignment.CENTER);//居中
        titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
        titleStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());//设置颜色（黄色）
        titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        titleStyle.setBorderRight(BorderStyle.THIN);//设置右边框
        titleStyle.setBorderBottom(BorderStyle.THIN);
        titleStyle.setRightBorderColor(IndexedColors.GREEN.getIndex());
        titleStyle.setBottomBorderColor(IndexedColors.GREEN.getIndex());
//        titleStyle.setAlignment(HorizontalAlignment.CENTER);
//        titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        titleStyle.setWrapText(true);
        return titleStyle;
    }

    @Override
    public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);//居中
        style.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
        style.setBorderRight(BorderStyle.THIN);//设置右边框
        style.setBorderBottom(BorderStyle.THIN);
        style.setRightBorderColor(IndexedColors.GREEN.getIndex());
        style.setBottomBorderColor(IndexedColors.GREEN.getIndex());
//        style.setAlignment(CellStyle.ALIGN_CENTER);
//        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        style.setDataFormat(STRING_FORMAT);
        if (isWarp) {
            style.setWrapText(true);
        }
        return style;
    }

    @Override
    public CellStyle getHeaderStyle(short color) {
        CellStyle titleStyle = workbook.createCellStyle();
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 12);
        titleStyle.setFont(font);
        titleStyle.setAlignment(HorizontalAlignment.CENTER);//居中
        titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
//        titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
//        titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        return titleStyle;
    }

    @Override
    public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);//居中
        style.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
        style.setBorderRight(BorderStyle.THIN);//设置右边框
        style.setBorderBottom(BorderStyle.THIN);
        style.setRightBorderColor(IndexedColors.GREEN.getIndex());
        style.setBottomBorderColor(IndexedColors.GREEN.getIndex());
//        style.setAlignment(CellStyle.ALIGN_CENTER);
//        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        style.setDataFormat(STRING_FORMAT);
        if (isWarp) {
            style.setWrapText(true);
        }
        return style;
    }
}
